package com.example.leave.api;

import com.example.leave.api.dto.ApproverDto;
import com.example.leave.api.vo.ApprovalVo;
import com.example.leave.application.LeaveApplication;
import com.example.leave.domain.leave.aggregate.Leave;
import com.example.leave.infrastructure.mapper.ApproverMapper;
import com.example.leave.infrastructure.mapper.LeaveMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * TODO
 *
 * @author lxh
 * @date 2020/11/25 下午2:03
 **/
@RestController
@RequestMapping("/leave")
public class LeaveApi {
    private final ApproverMapper approverMapper;
    private final LeaveMapper leaveMapper;
    private final LeaveApplication leaveApplication;

    public LeaveApi(ApproverMapper approverMapper, LeaveMapper leaveMapper, LeaveApplication leaveApplication) {
        this.approverMapper = approverMapper;
        this.leaveMapper = leaveMapper;
        this.leaveApplication = leaveApplication;
    }

    @GetMapping("/approver")
    public ApproverDto findNextApprover(@Valid ApprovalVo vo) {
        Leave leave = leaveMapper.toLeave(vo);
        return approverMapper.toApproverDto(leaveApplication.findNextApprover(leave));
    }
}
